<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>hover下划线效果</title>
    <style>
        ul {
            list-style: none;
            margin: 0;
            padding: 0;
        }
        a {
            color: inherit;
            text-decoration: none;
        }
        .nav {
            display: flex;
            width: fit-content;
            margin: 50px auto 0;
            padding: 20px;
            border: 1px solid #000;
            gap: 20px;
        }
        .item a {
            transition: all 300ms;
            display: block;
            padding-bottom: 4px;                        /* 用于增加文字底部距离下划线的距离 */

            background-image: linear-gradient(          /* 使用背景渐变来实现hover下划线效果 */
                to right,
                #f00
            );
            background-size: 0% 1.5px;
            background-repeat: no-repeat;
            background-position: center bottom;
            &:hover {
                background-size: 100% 1.5px;
            }
        }
    </style>
</head>
<body>
    <ul class="nav">
        <li class="item">
            <a href="javascript:;">文件</a>
        </li>
        <li class="item">
            <a href="javascript:;">快捷键设置</a>
        </li>
        <li class="item">
            <a href="javascript:;">软件帮助</a>
        </li>
        <li class="item">
            <a href="javascript:;">你觉得这里面会有什么呢？</a>
        </li>
    </ul>
</body>
</html>